home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.10 Oct 90 / NewToolBox.π / NewToolBox.Lib / LPic.Asm < prev    next >
Encoding:
Assembly Source File  |  1989-09-02  |  6.6 KB  |  223 lines  |  [TEXT/KAHL]

  1. ;*************************************
  2. ;*   P I C T U R E   M A N A G E R   *
  3. ;*************************************
  4.  
  5. INCLUDE Library.Txt
  6.  
  7. ;--------------------------------
  8. ; ***   Externals Definition  ***
  9. ;-------------------------------- 
  10.  
  11. XDEF InstalPict
  12. XDEF DrawPicts
  13. XDEF FindPict
  14.        
  15. ;-------------------------------
  16. ; ******  Picture Record  ******
  17. ;------------------------------- 
  18.  
  19. ; Picture = Record  { 10 bytes}
  20. ;{  0}       picSize : INTEGER
  21. ;{  2}       picFrame : Rect 
  22.  
  23. ;-------------------------------
  24. ;******  Pic Aux Record ********
  25. ;------------------------------- 
  26.  
  27. ;AuxPicRec = Record {16}
  28. ;{0}    PID            :INTEGER
  29. ;{2}    thePic        :PicHandle
  30. ;{6}    nextPic        :AuxPicHandle
  31. ;{10}   tMode        :INTEGER
  32. ;{12}    destRect    :Rect
  33.     
  34. ;---------------------------------------------------------------------------    
  35. ;FUNCTION InstalPict(PicID:INTEGER;whichWindow:WindowPtr):OSErr;
  36. ;---------------------------------------------------------------------------
  37.  
  38. ;-------------------------------
  39. ; Parameters
  40. ;-------------------------------
  41.  
  42. whichWindow         EQU 8
  43. PicID                 EQU 12
  44.  
  45. ;-------------------------------
  46. ; Local Variables
  47. ;-------------------------------
  48.  
  49. theHandle     EQU -10
  50. theNPict      EQU -6
  51. error         EQU -2
  52.  
  53. ;-------------------------------
  54.  
  55. InstalPict
  56.     LINK A6,#-10               ;
  57.     MOVEM.L A2-A4/D3-D7,-(SP)  ;
  58.     MOVE.W #noErr,error(A6)    ;                
  59.     SUBQ.L #4,SP               ;place for PicHdl
  60.     MOVE.W PicID(A6),-(SP)     ;pic ID
  61.     _GetPicture                ;read it...
  62.     MOVE.L (SP)+,A3            ;
  63.     SUBQ.L #2,SP               ;
  64.     _ResError                  ;
  65.     MOVE.W (SP)+,error(A6)     ;
  66.     BNE @0                     ;if error :go @0
  67.     MOVE.L A3,-(SP)            ;now, we detach our
  68.     _DetachResource            ;pic resource from the
  69.     SUBQ.L #2,SP               ;resource list
  70.     _ResError                  ;if an error occurs
  71.     MOVE.W (SP)+,error(A6)     ;we report it
  72.     BNE @0                     ;and we abort.
  73.     MOVE.L A3,theNPict(A6)     ;
  74.     MOVE.L whichWindow(A6),A0  ;
  75.     MOVE.L WrefCon(A0),A0       ;
  76.     MOVE.L (A0),A0               ;we find the pict
  77.     MOVE.L WPic(A0),A2           ;list for this window                    
  78.     MOVEA.L (A2),A3            ;
  79.     CMPI.L #NIL,thePic(A3)     ;no pict , go @1
  80.     BEQ @1                     ;
  81.     
  82. @3
  83.     CMPI.L #NIL,nextPic(A3) ;
  84.     BEQ @2                  ;we must find
  85.     MOVEA.L nextPic(A3),A3  ;the last pic AuxRec
  86.     MOVEA.L (A3),A3         ;of the list
  87.     BRA @3                  ;   
  88. @2
  89.     MOVEQ #SizePicAuxRec,D0 ;
  90.     _NewHandle              ;create a new
  91.     MOVE.W D0,error(A6)     ;pic AuxRec
  92.     BNE @0                  ;
  93.     MOVE.L A0,nextPic(A3)   ;
  94.     MOVEA.L A0,A3           ;
  95.     MOVEA.L (A3),A3         ;
  96.     MOVE.W picID(A6),PID(A3);
  97.     MOVE.L theNPict(A6),thePic(A3);
  98.     MOVE.L theNPict(A6),A0    ;
  99.     MOVE.L (A0),A0            ;
  100.     MOVE.L picFrame(A0),destRect(A3);
  101.     MOVE.L picFrame+4(A0),destRect+4(A3);
  102.     MOVE.L #NIL,nextPic(A3) ;
  103.     CLR.W tMode(A3)            ;
  104.     BRA @0  
  105. @1  
  106.     MOVE.W picID(A6),PID(A3);pic AuxRec already exists
  107.     MOVE.L theNPict(A6),thePic(A3);
  108.     MOVE.L theNPict(A6),A0    ;we initialize its fields
  109.     MOVE.L (A0),A0            ;
  110.     MOVE.L picFrame(A0),destRect(A3);
  111.     MOVE.L picFrame+4(A0),destRect+4(A3);
  112.     MOVE.L #NIL,nextPic(A3);
  113.     CLR.W tMode(A3)           ;    
  114. @0
  115.     MOVE.W error(A6),D0        ;
  116.     MOVEM.L (SP)+,A2-A4/D3-D7  ;
  117.     UNLK A6                    ;
  118.     MOVE.L (SP)+,A1            ;
  119.     ADD.L #6,SP                ;
  120.     MOVE.W D0,(SP)             ;
  121.     JMP(A1)                    ;
  122.     
  123. ;---------------------------------------------------------------------------    
  124. ;PROCEDURE DrawPicts(whichWindow:WindowPtr);
  125. ;---------------------------------------------------------------------------
  126.  
  127. ;-------------------------------
  128. ; local variables
  129. ;-------------------------------
  130.  
  131. AuxPicHdl   EQU -4
  132.  
  133. ;-------------------------------
  134.  
  135. DrawPicts
  136.     LINK A6,#-4                ;
  137.     MOVEM.L A2-A4/D3-D7,-(SP)  ;   
  138.     MOVE.L whichWindow(A6),A0  ;
  139.     MOVE.L WrefCon(A0),A0        ;
  140.     MOVE.L (A0),A0                ;
  141.     MOVE.L WPic(A0),A3            ;the first
  142.     MOVE.L A3,AuxPicHdl(A6)     ;pic AuxRec
  143.     MOVE.L (A3),A3              ;for this window
  144.     CMPI.L #NIL,thePic(A3)      ;no pict for this
  145.     BEQ @0                      ;window, go @0    
  146. @3  
  147.     MOVE.W tMode(A3),-(SP)        ;
  148.     _PenMode                    ;we set the pen mode
  149.     MOVE.L AuxPicHdl(A6),A3     ;before drawing
  150.     MOVE.L (A3),A3              ; 
  151.     MOVE.L thePic(A3),-(SP)     ;
  152.     PEA destRect(A3)            ;
  153.     _DrawPicture                ;
  154.     _PenNormal                    ;
  155.     MOVE.L AuxPicHdl(A6),A3     ;
  156.     MOVE.L (A3),A3              ;
  157.     CMPI.L #NIL,nextPic(A3)     ;another pict to draw
  158.     BEQ @0                      ;no so go @0
  159.     MOVEA.L nextPic(A3),A3      ;
  160.     MOVE.L A3,AuxPicHdl(A6)     ;
  161.     MOVEA.L (A3),A3             ;
  162.     BRA @3                      ;
  163. @0
  164.     MOVEM.L (SP)+,A2-A4/D3-D7   ;
  165.     UNLK A6                     ;
  166.     MOVE.L (SP)+,A0             ;
  167.     ADD.L #4,SP                 ;
  168.     JMP (A0)                    ;    
  169.      
  170. ;---------------------------------------------------------------------------    
  171. ;FUNCTION FindPict(thePoint:Point;whichWindow:WindowPtr):PicHandle;
  172. ;---------------------------------------------------------------------------
  173.  
  174. ;-------------------------------
  175. ; Parameters
  176. ;-------------------------------
  177.  
  178. thePoint    EQU 12
  179.  
  180. ;-------------------------------
  181. ; Local Variables
  182. ;-------------------------------
  183.  
  184. theFPic        EQU -4
  185.  
  186. ;-------------------------------
  187.  
  188. FindPict
  189.     LINK A6,#-4               ;
  190.     MOVEM.L A2-A4/D3-D7,-(SP) ;
  191.     MOVE.L #NIL,A1            ;
  192.     MOVE.L whichWindow(A6),A0 ;
  193.     MOVE.L WrefCon(A0),A0        ;
  194.     MOVE.L (A0),A0                ;
  195.     MOVE.L WPic(A0),A3            ;
  196.     MOVEA.L (A3),A3             ;
  197.     CMPI.L #NIL,thePic(A3)      ;
  198.     BEQ @0                      ;    
  199. @3
  200.     MOVE.L thePic(A3),A0        ;
  201.     MOVE.L A0,theFPic(A6)       ;    
  202.     SUBQ.L #2,SP                ;
  203.     MOVE.L thePoint(A6),-(SP)   ;
  204.     PEA destRect(A3)            ;do we cliked
  205.     _PtInRect                   ;in this pict ?
  206.     TST.B (SP)+                    ;
  207.     BNE @1                      ;yes, so go @1
  208.     CMPI.L #NIL,nextPic(A3)     ;no, next pict
  209.     BEQ @0                      ;in the (if any)
  210.     MOVEA.L nextPic(A3),A3      ;if not, go @0
  211.     MOVEA.L (A3),A3             ;
  212.     BRA @3                      ;    
  213. @1
  214.     MOVE.L theFPic(A6),A1       ;we've found it                                  
  215. @0
  216.     MOVEM.L (SP)+,A2-A4/D3-D7   ;
  217.     UNLK A6                     ;
  218.     MOVE.L (SP)+,A0             ;
  219.     ADD.L #8,SP                 ;
  220.     MOVE.L A1,(SP)              ;
  221.     JMP (A0)                    ; 
  222.     
  223. END